package com.example.common.constants;

/**
 * @author: Allen
 * @create: 2025/5/28 17:49
 * @description: 通用返回处理带错误码
 **/
public class RetResult<T> {
    private final Ret ret;
    private T data;

    public RetResult(Ret ret) {
        this.ret = ret;
    }
    public RetResult(Ret ret, T data) {
        this.ret = ret;
        this.data = data;
    }

    public Ret getRet() {
        return ret;
    }

    public T get() {
        return data;
    }

    public static <T> RetResult<T> success(T data) {
        return new RetResult<T>(Ret.Success, data);
    }
    public static <T> RetResult<T> error(Ret ret) {
        return new RetResult<T>(ret);
    }

    public boolean isSuccess() {
        return ret == Ret.Success;
    }
    public boolean isError() {
        return ret != Ret.Success;
    }
}
